// ========================
// RSDK Project Sonic CD's scrapped rounds
// Script Name: ConveyorPlatform
// Author: SCDU
// ========================

// ========================
// Aliases
// ========================

#alias Object.Value0	:	Object.Timer
#alias Object.Value1	:	Object.XOffset
#alias Object.Value2	:	Object.YOffset


#alias Player.Value0		:	Player.Rings

// Collision
#alias 1	:	PLAYER_COL_FLOOR
#alias 4	:	PLAYER_COL_ROOF

// Tile Info
#alias 1	:	TILEINFO_DIRECTION
#alias 6	:	TILEINFO_ANGLEA
	
#alias 1	:	SFX_S_SHOT


#alias 0 : MOVE_RIGHT
#alias 1 : MOVE_DOWN
#alias 2 : MOVE_LEFT
#alias 3 : MOVE_UP

#alias 4 : MOVE_RU
#alias 5 : MOVE_RD
#alias 6 : MOVE_LU
#alias 7 : MOVE_LD

// ========================
// Function Declarations
// ========================


// ========================
// Function Definitions
// ========================


// ========================
// Subs
// ========================

sub ObjectMain
	Object.Timer = 1
	TempValue2   = Object.XPos
	TempValue2 >>= 16

	TempValue3   = Object.YPos
	TempValue3 >>= 16
	
	TempValue0 = Object.Xpos
	TempValue0 >>=16	
	TempValue1 = Object.Ypos
	TempValue1 >>=16

	//Player.score = TempValue0
	//Player.Rings = TempValue1
	
	TempValue0 = 4018
	TempValue0 <<=16	
	TempValue1 = 460
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_RU
			else
				Object.PropertyValue = MOVE_UP
			end if
		end if
	end if
	
	TempValue0 = 4096
	TempValue0 <<=16	
	TempValue1 = 382
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_RD
			else
				Object.PropertyValue = MOVE_RU
			end if
		end if
	end if
	
	TempValue0 = 4174
	TempValue0 <<=16	
	TempValue1 = 460
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_DOWN
			else
				Object.PropertyValue = MOVE_RD
			end if
		end if
	end if
	
	TempValue0 = 4174
	TempValue0 <<=16	
	TempValue1 = 814
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_LEFT
			else
				Object.PropertyValue = MOVE_DOWN
			end if
		end if
	end if
	
	TempValue0 = 4018
	TempValue0 <<=16	
	TempValue1 = 814
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_UP
			else
				Object.PropertyValue = MOVE_LEFT
			end if
		end if
	end if
	// ---------------------------------- //
	TempValue0 = 5122
	TempValue0 <<=16	
	TempValue1 = 1212
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_RU
			else
				Object.PropertyValue = MOVE_UP
			end if
		end if
	end if
	
	TempValue0 = 5184
	TempValue0 <<=16	
	TempValue1 = 1150
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_RD
			else
				Object.PropertyValue = MOVE_RU
			end if
		end if
	end if
	
	TempValue0 = 5246
	TempValue0 <<=16	
	TempValue1 = 1212
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_DOWN
			else
				Object.PropertyValue = MOVE_RD
			end if
		end if
	end if
	
	TempValue0 = 5246
	TempValue0 <<=16	
	TempValue1 = 1596
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_LD
			else
				Object.PropertyValue = MOVE_DOWN
			end if
		end if
	end if
	
	TempValue0 = 5184
	TempValue0 <<=16	
	TempValue1 = 1658
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_LU
			else
				Object.PropertyValue = MOVE_LD
			end if
		end if
	end if
	
	TempValue0 = 5122
	TempValue0 <<=16	
	TempValue1 = 1596
	TempValue1 <<=16
	if Object.XPos == TempValue0
		if Object.YPos == TempValue1
			if Object[19].Value0 == 0
				Object.PropertyValue = MOVE_UP
			else
				Object.PropertyValue = MOVE_LU
			end if
		end if
	end if
	
	if	Object[19].Value0 == 0
		switch Object.PropertyValue
			case MOVE_RIGHT
				TempValue2 -=13
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos += Object.XOffset
			break
			case MOVE_LEFT
				TempValue2 +=12
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos -= Object.XOffset
			break
			case MOVE_DOWN
				TempValue3 -=12
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos += Object.YOffset
			break
			case MOVE_UP
				TempValue3 +=12	
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos -= Object.YOffset
			break
			
			case MOVE_RU
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos += Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos -= Object.YOffset
			break
			case MOVE_RD
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos += Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos += Object.YOffset
			break
			case MOVE_LU
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos -= Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos -= Object.YOffset
			break
			case MOVE_LD
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos -= Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos += Object.YOffset
			break
		end switch
	else	
		switch Object.PropertyValue
			case MOVE_RIGHT
				TempValue2 -=13
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos -= Object.XOffset
			break
			case MOVE_LEFT
				TempValue2 +=12
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos += Object.XOffset
			break
			case MOVE_DOWN
				TempValue3 -=12
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos -= Object.YOffset
			break
			case MOVE_UP
				TempValue3 +=12	
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos += Object.YOffset
			break
			
			case MOVE_RU
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos -= Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos += Object.YOffset
			break
			case MOVE_RD
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos -= Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos -= Object.YOffset
			break
			case MOVE_LU
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos += Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos += Object.YOffset
			break
			case MOVE_LD
				Object.XOffset = Object.Timer
				Object.XOffset <<= 16
				Object.Xpos += Object.XOffset
				Object.YOffset = Object.Timer
				Object.YOffset <<= 16
				Object.Ypos -= Object.YOffset
			break
		end switch
	end if
end sub


sub ObjectPlayerInteraction
	if Object.Value3 == 1
		if Object[19].Value0 == 0
			PlayerObjectCollision(C_TOUCH, -16, -10, 16, 8)
			if CheckResult == true
					switch Object.PropertyValue
						case MOVE_RIGHT
						case MOVE_RIGHT2
							Player.XPos += Object.XOffset
							break
						case MOVE_LEFT
						case MOVE_LEFT2
							Player.XPos -= Object.XOffset
							break
						case MOVE_UP
						case MOVE_UP2
							TempValue0 = -16
							TempValue0 <<= 16
							TempValue0 += Object.YPos
							TempValue0 += Object.YOffset
							Player.YPos = TempValue0
							break
						case MOVE_DOWN
						case MOVE_DOWN2
							TempValue0 = -16
							TempValue0 <<= 16
							TempValue0 += Object.YPos
							TempValue0 += Object.YOffset
							Player.YPos = TempValue0
							break
						
						case MOVE_LU
							Player.XPos -= Object.XOffset
							Player.YPos -= Object.YOffset
							break
						case MOVE_RU
							Player.XPos += Object.XOffset
							Player.YPos -= Object.YOffset
							break
						case MOVE_LD
							Player.XPos -= Object.XOffset
							Player.YPos += Object.YOffset
							break
						case MOVE_RD
							Player.XPos += Object.XOffset
							Player.YPos += Object.YOffset
							break
					end switch
			end if
		else
			PlayerObjectCollision(C_TOUCH, -16, -10, 16, 8)
			if CheckResult == true
				switch Object.PropertyValue
					case MOVE_RIGHT
					case MOVE_RIGHT2
						Player.XPos -= Object.XOffset
						break
					case MOVE_LEFT
					case MOVE_LEFT2
						Player.XPos += Object.XOffset
						break
					case MOVE_UP
					case MOVE_UP2
						TempValue0 = -16
						TempValue0 <<= 16
						TempValue0 += Object.YPos
						TempValue0 += Object.YOffset
						Player.YPos = TempValue0
						break
					case MOVE_DOWN
					case MOVE_DOWN2
						TempValue0 = -16
						TempValue0 <<= 16
						TempValue0 += Object.YPos
						TempValue0 += Object.YOffset
						Player.YPos = TempValue0
						break
					
					case MOVE_LU
						Player.XPos += Object.XOffset
						Player.YPos += Object.YOffset
						break
					case MOVE_RU
						Player.XPos -= Object.XOffset
						Player.YPos += Object.YOffset
						break
					case MOVE_LD
						Player.XPos += Object.XOffset
						Player.YPos -= Object.YOffset
						break
					case MOVE_RD
						Player.XPos -= Object.XOffset
						Player.YPos -= Object.YOffset
						break
				end switch
			end if
		end if 
	end if 
	PlayerObjectCollision(C_PLATFORM, -16, -8, 16, 8)
	if CheckResult == PLAYER_COL_FLOOR
		Object.Value3 = 1
	else
		Object.Value3 = 0
	end if
end sub


sub ObjectDraw
    DrawSprite(0)    
end sub


sub ObjectStartup
    LoadSpriteSheet("R4.5/Objects.gif")
	SpriteFrame(-16, -8, 32, 16, 224, 88)
	
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[ConveyorPlatform]
			Object[ArrayPos0].Priority = 1
		end if
		
		ArrayPos0++
	loop
end sub


// ========================
// Editor Subs
// ========================

sub RSDKEdit
    if editor.returnVariable == true
        switch editor.variableID
        case EDIT_VAR_PROPVAL	// property value
        case 0	// property value
            checkResult = object.propertyValue
            break
        end switch
    else
        switch editor.variableID
        case EDIT_VAR_PROPVAL	// property value
        case 0	// property value
            object.propertyValue = editor.variableValue
            break
        end switch
    end if
end sub


sub RSDKDraw
    DrawSprite(0)
end sub


sub RSDKLoad
    LoadSpriteSheet("R4.5/Objects.gif")
	SpriteFrame(-16, -8, 32, 16, 224, 88)		// #0 - "Script" Icon
    
	AddEditorVariable("moveType")
	SetActiveVariable("moveType")
	AddEnumVariable("Move Right", 0)
	AddEnumVariable("Move Down", 1)
	AddEnumVariable("Move Left", 2)
	AddEnumVariable("Move Up", 3)
	AddEnumVariable("Move Up Right", 4)
	AddEnumVariable("Move Down Right", 5)
	AddEnumVariable("Move Up Left", 6)
	AddEnumVariable("Move Down Left", 7)
end sub
